package com.lz.football.module.playerCenter
{
	import com.common.stdlib.ArrayUtil;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.constants.ClubConst;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.PlayerCenterEvent;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.liangzhong.model.playerCenter.PlayerCenterDataConstant;
	import com.liangzhong.model.playerCenter.PlayerCenterDataManager;
	import com.liangzhong.model.playerCenter.vo.PlayerVo;
	import com.liangzhong.model.type.GoodsType;
	import com.liangzhong.model.type.OtherGoodType;
	import com.lz.football.module.base.IComponent;
	import com.lz.football.module.playerCenter.ModificationNumber.ModificationNumber;
	import com.lz.football.module.playerCenter.item.PlayerEquipItem;
	
	import common.BaseView.BaseView;
	import common.BaseView.DisplayMouseEventManager;
	import common.base.GoodsUsePanel;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import lz.controls.Alert;
	import lz.controls.nick.PagePanel;
	
	/**
	 *球员中心列表 
	 * @author Administrator
	 * 
	 */	
	public class PlayerCenterListView extends  BaseView implements IComponent
	{
		//		/**
		//		 * 
		//		 */
		//		private var _skin:MovieClip;
		
		/**
		 *关闭按钮 
		 */		
		public static var closeBtn :SimpleButton;
		/**
		 *修改号码 
		 */
		private var modificationBtn:SimpleButton;
		/**
		 *解雇 
		 */
		private var layoffBtn:SimpleButton;
		/**
		 *退役 
		 */
		private var retireBtn:SimpleButton;
		/**
		 *强力恢复 
		 */
		public static var restoreBtn:SimpleButton;
		/**
		 *阵容设置按钮 
		 */
		public static var battleBtn:SimpleButton;
		/**
		 *列表容器 
		 */
		private var listcontain:MovieClip;
		/**
		 *球员数量 
		 */
		private var playNumber:TextField;
		/**
		 * listItem
		 */
		private var _listVec:Vector.<ListItem>;
		//		/**
		//		 *滚动条 
		//		 */
		//		private var _scrollBar:ScrollBarByMc;
		//		private var _target:Sprite;
		/**
		 *球员中心管理器 
		 */
		private var _playerCenterDataManager:PlayerCenterDataManager;
		/**
		 *选中的球员  
		 */
		private var _selectItem:ListItem;
		/**
		 *修改号码 
		 */
		private var _modificationView:ModificationNumber;
		/**
		 *球员list 
		 */
		private var _playerList:Array;
		/**
		 *体力 
		 */
		private var progressbar:MovieClip;
		/**
		 * 装备容器
		 */
		private var equipContain:MovieClip;
		/**
		 *球员卡容器 
		 */
		private var playerCard:MovieClip;
		
		/**
		 * 选择了装备  
		 */
		private var _selectEquip:PlayerEquipItem;
		/**
		 *装备List 
		 */
		private var _equipVec:Vector.<PlayerEquipItem>;
		/**
		 * 
		 */
		private var _goodusePanel:GoodsUsePanel;
		/**
		 *球员卡 
		 */
		private var _card:PlayerCard;
		/**
		 *体力 
		 */
		private var powerBtn:SimpleButton;
		/**
		 *buff 
		 */
		private var buffBtn:SimpleButton;
		/**
		 * 
		 */
		private var page:MovieClip;
		/**
		 * 
		 */
		private var _page:PagePanel;
		public function PlayerCenterListView()
		{
			super();
		}
		
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.modul.playerCenter.MainView");
			this.addChild(symbolSkin);
			_windowBg = symbolSkin.playerCenterBg;
			isDrag = true;
			isCloseBtn = true;
			_viewWidth = symbolSkin.width;
			_viewHeight = symbolSkin.height;
			onResizeHandler();
			moveClose(715,25);
			modificationBtn= symbolSkin.modificationBtn;
			layoffBtn = symbolSkin.layoffBtn;
			retireBtn = symbolSkin.retireBtn;
			restoreBtn = symbolSkin.restoreBtn;
			listcontain = symbolSkin.listcontain;
			battleBtn = symbolSkin.battleBtn;
			playNumber = symbolSkin.playNumber;
			page = symbolSkin.page;
			_playerCenterDataManager = AppData.getInstance().playerCenterDataManager;
			equipContain = symbolSkin.infoMc.equipContain;
			_card = new PlayerCard();
			_card.initUI();
			symbolSkin.infoMc.playerCard.addChild(_card);
			powerBtn = symbolSkin.infoMc.powerBtn;
			buffBtn = symbolSkin.infoMc.buffBtn
			initEquipItem();
			initPage();
			initItem();
			
			upDataPlayer();
			//			DisplayMouseEventManager.instance.addTipsDisplay(modificationBtn,"修改球衣号码");
			//			DisplayMouseEventManager.instance.addTipsDisplay(layoffBtn,"将球员从球员列表中删除");
			//			DisplayMouseEventManager.instance.addTipsDisplay(retireBtn,"退役球员可获得声望");
			DisplayMouseEventManager.instance.addTipsDisplay(restoreBtn,"恢复所有球员体力");
			addEvtListener();
			//@lake
			closeBtn = _closeBtn;
		}
		private function initPage():void
		{
			_page = new PagePanel();
			_page.initUI("com.lz.commonUI.turnPage_white");
			_page.callBack = turnPage;
			_page.max = 3;
			page.addChild(_page);
		}
		/**
		 *初始化Item 
		 * 
		 */
		private function initItem():void
		{
			_listVec = new Vector.<ListItem>();
			var item:ListItem;
			var i:int;
			for(i = 0;i < 16;i++)
			{
				item = new ListItem();
				item.initUI();
				item.addBar();
				item.y = (item.height + 4) * int(i /4);
				item.x = (item.width + 2) * (i %4);
				//				item.setBg(i);
				
				//				item.callBack = selectItem;
				//				listcontain.addChild(item);
				//				item.data = _playerList[i];
				_listVec.push(item);
				//				if(_playerList[i].physical < _playerList[i].maxphysical)
				//				{
				//					restoreBtnStatus(true);
				//				}
				//				if(i == 0)
				//					selectItem(item);
			}
			//			for(i;i < 16 ;i++)
			//			{
			//				item = new ListItem();
			//				item.initUI();
			//				item.y = (item.height + 8) * int(_target.numChildren /4);
			//				item.x = (item.width + 2) * (_target.numChildren %4);
			//				item.reset();
			//				_target.addChild(item);
			//				_listVec.push(item);
			//			}
			//			if(_playerCenterDataManager.playerCenterVo.players <  PlayerCenterDataConstant.MAX_PLAYER_NUMBER)
			//			{
			//				item = new ListItem();
			//				item.initUI();
			//				item.y = 26 * _target.numChildren;
			//				item.addPlayerNumber();
			//				item.callBack = addPlayerNumber;
			//				_target.addChild(item);
			//				_listVec.push(item);
			//			}
			
			
			//			_scrollBar.targetHeight = (item.height + 8)*Math.ceil(_target.numChildren /4);
			//			_scrollBar.upData();
			//			planyerNumberChange();
			//			list.x = 50;
			//			list.y = 100;
		}
		
		/**
		 *初始化装备  
		 * 
		 */
		private function initEquipItem():void
		{
			_equipVec = new Vector.<PlayerEquipItem>();
			var item:PlayerEquipItem;
			for(var i:int = 0;i < 4;i++)
			{
				item = new PlayerEquipItem();
				item.initUI("com.lz.commonUI.ItemFrame");
				item.x = (item.width + 5)*(i % 2)
				item.y = (item.width + 2) * int (i/2);
				item.type = i;
				item.addLock();
				item.callBack = selectEquip;
				equipContain.addChild(item);
				_equipVec.push(item);
			}
		}
		
		
		/************装备************************/
		/**
		 *选择了装备  
		 * 
		 */
		private function selectEquip($item:PlayerEquipItem,$isDouble:Boolean):void
		{
			if(_selectItem == null)
			{
				Alert.showErrorTip("选择球员");
				return ;
			}
			if(_selectEquip != null)
			{
				if(int(_selectEquip.type /2)!= int($item.type/2))
				{
					Alert.showErrorTip("选择的类型不同");
					return;
				}
			}
			_goodusePanel = GoodsUsePanel.inistance
			if(_selectEquip == null)
			{
				if(_selectEquip!= null)_selectEquip.select = false;
				_selectEquip = $item;
				_selectEquip.select = true;
				_goodusePanel.initPlace();
				_goodusePanel.x= ((GlobalDef.StageWidth - _goodusePanel.width) >> 1) -300;
				if(int(_selectEquip.type /2) == 1)//FOOTWEAR鞋袜卡
					_goodusePanel.setShowGoodsType(GoodsType.FOOTWEAR);//AppData.getInstance().bagDataManager.getGoodsListByTwoTypes(GoodsType.FOOTWEAR);
				else//属性卡
					_goodusePanel.setShowGoodsType(GoodsType.ATTRIBUTE)//AppData.getInstance().bagDataManager.getGoodsListByTwoTypes(GoodsType.ATTRIBUTE);
				_goodusePanel.callBack = useGoods;
				_goodusePanel.addEventListener(Event.REMOVED_FROM_STAGE,onRemoveGoodsUsePanelHandler);
				_goodusePanel.showBtn(GoodsUsePanel.BTN_TYPE_5);
				return;
			}
			
			if(_selectEquip!= null)_selectEquip.select = false;
			_selectEquip = $item;
			_selectEquip.select = true;
			if($isDouble &&　$item.data != null)//双击了装备，则换下装备
			{
				var playerId:int = (_selectItem.data as PlayerVo).playerid;
				var cellId:int = 0;
				var posid:int = (_selectEquip.type % 2) == 0 ? 1:2;//位置
				var ntype:int = int(_selectEquip.type / 2) == 0? 3:2;//道具类型：3为属性卡 2为鞋袜卡
				
				AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(
					PlayerCenterEvent.REPLACE_EQUIP,{playerId:playerId,cellId:cellId,posid:posid,ntype:ntype}));
			}
		}
		/**
		 *使用物品（更换装备） 
		 * 
		 */
		private function useGoods($goods:GoodsVo):void
		{
			if($goods == null)return;
			if(_selectItem.data == null || _selectItem == null)
			{
				Alert.showErrorTip("选择球员");
				return
			}
			if(_selectEquip == null)
			{
				Alert.showErrorTip("选择装备类型");
				return;
			}
			var playerId:int = (_selectItem.data as PlayerVo).playerid;
			var cellId:int = $goods.pid;
			var posid:int = (_selectEquip.type % 2) == 0 ? 1:2;//位置
			var ntype:int = int(_selectEquip.type / 2) == 0? 3:2;//道具类型：3为属性卡 2为鞋袜卡
			AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(
				PlayerCenterEvent.REPLACE_EQUIP,{playerId:playerId,cellId:cellId,posid:posid,ntype:ntype}));
		}
		
		/**
		 * 物品使用面板移除 
		 * @param event
		 * 
		 */
		protected function onRemoveGoodsUsePanelHandler(event:Event = null):void
		{
			// TODO Auto-generated method stub
			if(_selectEquip != null)_selectEquip.select = false;
			_selectEquip = null;
		}
		
		/**
		 *显示装备信息 
		 * 
		 */
		private function showEquipInfo(star:PlayerVo):void
		{
			if(star.attr1 >0)
			{
				_equipVec[0].data = {goodsId:star.attr1,type:GoodsType.ATTRIBUTE,lock:star.attr1lock};
			}else
			{
				_equipVec[0].reset();
			}
			if(star.attr2 > 0)
			{
				_equipVec[1].data = {goodsId:star.attr2,type:GoodsType.ATTRIBUTE,lock:star.attr2lock};
			}else
			{
				_equipVec[1].reset();
			}
			if(star.equip1 > 0)
			{
				_equipVec[2].data = {goodsId:star.equip1,type:GoodsType.FOOTWEAR,lock:star.equip1lock};//GoodsType.FOOTWEAR
			}else
			{
				_equipVec[2].reset();
			}
			
			if(star.equip2 > 0)
			{
				_equipVec[3].data = {goodsId:star.equip2,type:GoodsType.FOOTWEAR,lock:star.equip2lock};
			}else
			{
				_equipVec[3].reset();
			}
			if(_selectEquip != null)
				_selectEquip.select = true;
		}
		/**
		 *更新装备信息 
		 * 
		 */
		public function updataEquipInfo($obj:Object):void
		{
			if(_selectItem == null)return;
			if((_selectItem.data as PlayerVo).playerid != $obj.playerId)return;
			//			showEquipInfo(_selectItem.data as PlayerVo);
			//			selectItem();
			
			var vo:PlayerVo = _selectItem.data as PlayerVo
			//			showPlayerInfo(vo);
			
			
			showEquipInfo(vo);
			_card.setData(vo);
			//更新物品使用面板
			//			if(_goodusePanel.parent)
			//			{
			//				if(int(_selectEquip.type /2) == 1)//FOOTWEAR鞋袜卡
			//					 _goodusePanel.setShowGoodsType(GoodsType.FOOTWEAR)//AppData.getInstance().bagDataManager.getGoodsListByTwoTypes(GoodsType.FOOTWEAR);
			//				else//属性卡
			//					_goodusePanel.setShowGoodsType(GoodsType.ATTRIBUTE)//_goodusePanel.setShowGoodsType(GoodsType.FOOTWEAR)AppData.getInstance().bagDataManager.getGoodsListByTwoTypes(GoodsType.ATTRIBUTE);
			//			}
			
		}
		/************装备end************************/
		/**
		 *显示基本信息 
		 * 
		 */		
		private function showPlayerInfo(star :PlayerVo):void
		{
			symbolSkin.infoMc.cPlayerName.text = star.starVo.name + "";
			//			symbolSkin.infoMc.ePlayerName.text = /*star.starVo.descplay +*/ "";
			
			symbolSkin.infoMc.Lv.text = star.level + "";
			symbolSkin.infoMc.physical.text = star.physical +"/"+ star.maxphysical;
			
			symbolSkin.infoMc.ability.text = star.ability + "";
			symbolSkin.infoMc.progressbar.progressbar.width = star.physical / (star.maxphysical <=0? 1:star.maxphysical) * 77;
			symbolSkin.infoMc.salary.text = star.salary+ "";
			if(star.status ==1)
			{
				buffBtn.visible = false;
				symbolSkin.infoMc.buffStatus.text = "状态：健康";
			}else
			{
				buffBtn.visible = true;
				symbolSkin.infoMc.buffStatus.text = "状态：";
			}
			if(star.physical >= star.maxphysical)
			{
				powerBtn.visible = false;
			}else
			{
				powerBtn.visible = true;
			}
			
		}
		/**
		 *选择了球员 
		 * @param $item
		 * 
		 */
		private function selectItem($item:ListItem):void
		{
			if(_selectItem != null)
				_selectItem.select = false;
			_selectItem = $item;
			_selectItem.select = true;
			var vo:PlayerVo = $item.data as PlayerVo
			showPlayerInfo(vo);
			
			
			showEquipInfo(vo);
			_card.setData(vo);
		}
		/**
		 *增加球员数 
		 * @param $item
		 * 
		 */
		private function addPlayerNumber($item:ListItem):void
		{
			var num:int = _playerCenterDataManager.playerCenterVo.players -  13// 14 - 1;
			if(num >= 10)num = 10;
			var pow:int = Math.pow(2,num);
			if(pow > AppData.getInstance().clubDatamanager.clubInfo.cashpoint)
			{
//				Alert.showErrorTip("点券不足，不可以增加球员名额！");
				Alert.noCashAlert("现有点券不足" +pow+"点,是否前往充值？");
				return;
			}
			//			Alert.showErrorTip("增加球员数");
			Alert.show("花费"+pow+"点券来增加一个球员名额，确定么","",Alert.NO,GlobalDef.AlertContainer,addCell);
			function addCell($type:int):void
			{
				if($type == Alert.YES)
					AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.ADD_PLAYER_CELL));
			}
		}
		/**
		 *球员数量改变 
		 * 
		 */
		public function planyerNumberChange():void
		{
			playNumber.text ="球员数量："+ _playerCenterDataManager.playerCenterVo.playersNumber +"/" + _playerCenterDataManager.playerCenterVo.players;
		}
		
		
		override public function addEvtListener():void
		{
			layoffBtn.addEventListener(MouseEvent.CLICK,onLayoffHandler);
			retireBtn.addEventListener(MouseEvent.CLICK,onRetireHandler);
			restoreBtn.addEventListener(MouseEvent.CLICK,onRestoreHandler);
			//			modificationBtn.addEventListener(MouseEvent.CLICK,onModificationHandler);
			this.addEventListener(Event.REMOVED_FROM_STAGE,onRemoveStageHandler);
			powerBtn.addEventListener(MouseEvent.CLICK,onPowerHandler);
			buffBtn.addEventListener(MouseEvent.CLICK,onBuffHandler);
			battleBtn.addEventListener(MouseEvent.CLICK,onOpenBattleBtnHanlder);
			
			DisplayMouseEventManager.instance.addTipsDisplay(powerBtn,"体力为1时会严重影响上场球员发挥，并且有一定几率使其受伤！");
			DisplayMouseEventManager.instance.addTipsDisplay(buffBtn,"受伤状态下的球员发挥会收到严重影响！\n体力为1时场上球员有几率受伤！");
			DisplayMouseEventManager.instance.addTipsDisplay(retireBtn,"退役球员获得声望和有几率获得球魂！");
			
		}
		
		/**
		 *打开阵容设置面板 
		 * @param event
		 * 
		 */
		protected function onOpenBattleBtnHanlder(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			this.dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.ADD_BATTLE_VIEW,null,true));
		}
		/**
		 *增加体力 
		 * @param event
		 * 
		 */
		protected function onPowerHandler(event:MouseEvent):void
		{
			if(_goodusePanel == null)_goodusePanel = GoodsUsePanel.inistance;
			_goodusePanel.initPlace();
			//			_goodusePanel.goodsList = AppData.getInstance().bagDataManager.getGoodsListByTwoTypes(GoodsType.OTHER,OtherGoodType.PHYSICAL);
			_goodusePanel.setshowphysical(GoodsType.OTHER,OtherGoodType.PHYSICAL,4);
			
			_goodusePanel.callBack = usePowerGoods;
			_goodusePanel.showBtn(GoodsUsePanel.BTN_TYPE_7);
			onRemoveGoodsUsePanelHandler();
		}
		/**
		 * 改变状态 
		 * @param event
		 * 
		 */
		protected function onBuffHandler(event:MouseEvent):void
		{
			if(_selectItem==null)return;
			if(_goodusePanel == null)_goodusePanel = GoodsUsePanel.inistance;
			_goodusePanel.initPlace();
			//			_goodusePanel.goodsList = AppData.getInstance().bagDataManager.getGoodsListByTwoTypes(GoodsType.OTHER,OtherGoodType.MEDICALCARD);
			_goodusePanel.setShowGoodsType(GoodsType.OTHER,OtherGoodType.MEDICALCARD);
			
			_goodusePanel.callBack  = useBuffGoods;
			_goodusePanel.showBtn(GoodsUsePanel.BTN_TYPE_6);
			onRemoveGoodsUsePanelHandler();
			
		}
		/**
		 *使用体力物品增加体力 
		 * @param $goodsVo
		 * 
		 */
		private function usePowerGoods($goodsVo:GoodsVo):void
		{
			if(_selectItem==null)return;
			var vo:PlayerVo = _selectItem.data as PlayerVo
			if(vo.physical == vo.maxphysical)
			{
				Alert.showErrorTip("体力充沛，不需要回复");
				return;
			}
			if($goodsVo == null)
			{
				Alert.show("是否确定消耗5点券使该球员体力回复满。","",Alert.NO,GlobalDef.AlertContainer,useBuff);
				function useBuff($type:int):void
				{
					if($type == Alert.YES)
					{
						AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REPLY_PLAYER_POWER,
							{type:1,id:vo.playerid,cellId:0}));
					}
				}
				return;
			}
			var cellid:int ;
			cellid = $goodsVo.pid;
			AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REPLY_PLAYER_POWER,
				{type:1,id:vo.playerid,cellId:cellid}));
		}
		/**
		 *使用buff物品 
		 * @param $goodsVo
		 * 
		 */
		private function useBuffGoods($goodsVo:GoodsVo):void
		{
			if(_selectItem==null)return;
			var vo:PlayerVo = _selectItem.data as PlayerVo
			if(vo.status ==1)
			{
				Alert.showErrorTip("球员状态良好，不需要回复");
				return;
			}
			if($goodsVo == null)
			{
				Alert.show("治疗该受伤球员需要花费25000欧元，确定吗？","",Alert.NO,GlobalDef.AlertContainer,useBuff);
				function useBuff($type:int):void
				{
					if($type == Alert.YES)
					{
						AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REPLY_BUFF,{type:1,id:vo.playerid,cellId:0}));
					}
				}
				return;
			}
			var cellid:int ;
			
			cellid = $goodsVo.pid;
			AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REPLY_BUFF,{type:1,id:vo.playerid,cellId:cellid}));
		}
		/**
		 *移除在面板 
		 * @param event
		 * 
		 */
		protected function onRemoveStageHandler(event:Event):void
		{
			// TODO Auto-generated method stub
			if(_modificationView != null && _modificationView.parent)
				_modificationView.parent.removeChild(_modificationView);
		}
		
		/**
		 *修改号码 
		 * @param event
		 * 
		 */
		protected function onModificationHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			if(_modificationView == null)
			{
				_modificationView = new ModificationNumber()
				_modificationView.initUI();
			}
			_modificationView.upDataList();
			GlobalDef.GameWindowContainer.addChild(_modificationView);
		}
		
		/**
		 * 强力回复体力 
		 * @param event
		 * 
		 */
		protected function onRestoreHandler(event:MouseEvent):void
		{
			
			var len:int = _playerList.length;
			var boo:Boolean = false;
			for(var i:int = 0;i < len;i++)
			{
				if(_playerList[i].physical < _playerList[i].maxphysical)
				{
					boo = true;
					break;
				}
			}
			if(true)
			{
				if(_goodusePanel == null)_goodusePanel = GoodsUsePanel.inistance;
				_goodusePanel.initPlace();
				//			_goodusePanel.goodsList = AppData.getInstance().bagDataManager.getGoodsListByTwoTypes(GoodsType.OTHER,OtherGoodType.PHYSICAL);
//				_goodusePanel.setShowGoodsType(GoodsType.OTHER,OtherGoodType.PHYSICAL);
				_goodusePanel.setshowphysical(GoodsType.OTHER,OtherGoodType.PHYSICAL,16);
				_goodusePanel.showBtn(GoodsUsePanel.BTN_TYPE_2);
				_goodusePanel.callBack = restorePhysical;
				
				//				Alert.show("确定花200点券强力回复体力么","",Alert.NO,GlobalDef.AlertContainer,restoreAlert);
			}
			else
			{
				Alert.showErrorTip("所有球员体力充沛，不需要回复");
			}
			onRemoveGoodsUsePanelHandler();
			//guide @lake 2013-11-19
			AppEventDispatcher.getInstance().dispatchEvt("Guide_openPhysicalUse");
		}
		/**
		 * 
		 * @param $type
		 * 
		 */
		private function restoreAlert($type:int):void
		{
			if($type == Alert.YES)
				AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REPLY_PLAYER_POWER,{type:2,cellId:0}));
		}
		private function restorePhysical($goodsVo:GoodsVo):void
		{
			if($goodsVo == null)
			{
				if(AppData.getInstance().clubDatamanager.clubInfo.cashpoint < 50)
				{
//					Alert.showErrorTip("点券不足，不可以回复");
					Alert.noCashAlert("现有点券不足50点，是否前往充值？");
					return ;
				}
				Alert.show("确定花50点券强力回复体力么","",Alert.NO,GlobalDef.AlertContainer,restoreAlert);
//				AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REPLY_PLAYER_POWER,{type:2,cellId:0}));
				return;
			}
			var cellid:int ;
			cellid = $goodsVo.pid;
			AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REPLY_PLAYER_POWER,
				{type:2,cellId:cellid}));
		}
		/**
		 * 退役 
		 * @param event
		 * 
		 */
		protected function onRetireHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			if(_selectItem == null || _selectItem.data == null)
			{
				Alert.showErrorTip("请选择需要退役的球员");
				return ;
			}
			var playervo:PlayerVo = _selectItem.data as PlayerVo;
			if(playervo.level < 25)
			{
				Alert.showErrorTip("球员25级才可以退役");
				return;
			}
			if(_playerCenterDataManager.playerIsBattlearray((_selectItem.data as PlayerVo).playerid))
			{
				Alert.showErrorTip("退役的球员在阵容中，不可以退役");
				return;
			}
			Alert.show("安排" + playervo.starVo.name+"退役，您可以获得"+ClubConst.playerRetireForReputation(playervo.color)+"声望","",Alert.NO,GlobalDef.AlertContainer,retireAlert);
			
		}
		/**
		 * 
		 * @param $type
		 * 
		 */
		private function retireAlert($type:int):void
		{
			
			if($type == Alert.YES)
			{
				retireBtn.removeEventListener(MouseEvent.CLICK,onRetireHandler);
				AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REMOVE_PLAYER,{type:1,id:(_selectItem.data as PlayerVo).playerid}));
			}
		}
		/**
		 * 解雇  
		 * @param event
		 * 
		 */
		protected function onLayoffHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			if(_selectItem == null || _selectItem.data == null)
			{
				Alert.showErrorTip("请选择需要解雇的球员");
				return ;
			}
			if(_playerCenterDataManager.playerIsBattlearray((_selectItem.data as PlayerVo).playerid))
			{
				Alert.showErrorTip("解雇的球员在阵容中，不可以解雇");
				return;
			}
			Alert.show("解雇"+(_selectItem.data as PlayerVo).starVo.name+"，确定吗？","",Alert.NO,GlobalDef.AlertContainer,LayoffAlert);
			
		}
		override public function onCloseHandler(event:MouseEvent):void
		{
			AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REMOVE_MODEL));
		}
		private function LayoffAlert($type:int):void
		{
			
			if($type == Alert.YES)
			{
				layoffBtn.removeEventListener(MouseEvent.CLICK,onLayoffHandler);
				AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REMOVE_PLAYER,{type:2,id:(_selectItem.data as PlayerVo).playerid}));
			}
		}
		override public function removeEvtListener():void
		{
			super.removeEvtListener();
			layoffBtn.removeEventListener(MouseEvent.CLICK,onLayoffHandler);
			retireBtn.removeEventListener(MouseEvent.CLICK,onRetireHandler);
			restoreBtn.removeEventListener(MouseEvent.CLICK,onRestoreHandler);
			//			modificationBtn.addEventListener(MouseEvent.CLICK,onModificationHandler);
			this.removeEventListener(Event.REMOVED_FROM_STAGE,onRemoveStageHandler);
			powerBtn.removeEventListener(MouseEvent.CLICK,onPowerHandler);
			buffBtn.removeEventListener(MouseEvent.CLICK,onBuffHandler);
			battleBtn.removeEventListener(MouseEvent.CLICK,onOpenBattleBtnHanlder);
			DisplayMouseEventManager.instance.removeTipsDisplay(restoreBtn);
			DisplayMouseEventManager.instance.removeTipsDisplay(powerBtn);
			DisplayMouseEventManager.instance.removeTipsDisplay(buffBtn);
			DisplayMouseEventManager.instance.removeTipsDisplay(retireBtn);
		}
		
		override public function destroyView():void
		{
			removeEvtListener();
			var item:ListItem;
			while(_listVec.length)
			{
				item = _listVec.pop();
				item.destroyView();
				item = null;
			}
			_listVec = null;
			var eI:PlayerEquipItem;
			while(_equipVec.length)
			{
				eI = _equipVec.pop();
				eI.destroyView();
				eI = null;
			}
			_page.destroyView();
			_page = null;
			_card.destroyView();
			_card = null;
			
			//			_scrollBar.destroyView();
			//			_scrollBar = null;
			//			
			//			_target = null;
			_selectItem = null;
			//			if(_modificationView != null)_modificationView.destroyView();
			//			_modificationView = null;
			
			//			if(this.parent)this.parent.removeChild(this);
			
			_playerList = null;
			
			
			symbolSkin = null;
			
			battleBtn = null;
			closeBtn = null;
			restoreBtn = null;
			super.destroyView();
		}
		
		/**
		 *删除球员 
		 * @param $obj
		 * 
		 */
		public function removePlayer($obj:Object):void
		{
			layoffBtn.addEventListener(MouseEvent.CLICK,onLayoffHandler);
			retireBtn.addEventListener(MouseEvent.CLICK,onRetireHandler);
			if(!$obj.status)return;
			//
			upDataPlayer();
			//			planyerNumberChange();
			
			
		}
		/**
		 * 更新球员
		 * 
		 */
		public function upDataPlayer():void
		{
			AppData.getInstance().playerCenterDataManager.firstBattlearraySortOn();
			_playerList = AppData.getInstance().playerCenterDataManager.playerList;
			planyerNumberChange();
			
			if(_playerList.length <= (_page.min - 1) * 16)_page.min = 1;
//			trace(AppData.getInstance().playerCenterDataManager.playerCenterVo.players);
//			_page.max = Math.ceil(_playerList.length/ 16);
//			if(_page.max <=0)
//				_page.max = 1;
//			if(_page.min >= _page.max)_page.min = _page.max;
			turnPage();
//			restoreBtnStatus(false);
//			var len:int;
//			var i:int;
//			len = _playerList.length;
//			for(i = 0;i < len;i++)
//			{
//				if(_playerList[i].physical < _playerList[i].maxphysical)
//				{
//					restoreBtnStatus(true);
//					break;
//				}
//			}
			//			restoreBtnStatus(false);
			//			
			//			if(_selectItem != null)
			//				_selectItem.select = false;
			//			_selectItem = null;
			//			var len:int = _listVec.length;
			//			var i:int = 0;
			//			for(i = 0;i < len;i++)
			//			{
			//				_listVec[i].reset();
			//			}
			
			//			len = _playerList.length;
			//			if(_playerList.length > _listVec.length)
			//				len = _listVec.length;
			//			for(i = 0;i < len;i++)
			//			{
			//				_listVec[i].data = _playerList[i];
			//				_listVec[i].callBack = selectItem;
			//				if(_playerList[i].physical < _playerList[i].maxphysical)
			//				{
			//					restoreBtnStatus(true);
			//				}
			//				if(i == 0)
			//					selectItem(_listVec[i]);
			//			}
		}
		/**
		 *增加球员格子 
		 * 
		 */
		public function addPlayerCell($obj:Object):void
		{
			if(!$obj.status)return;
			//if(_playerCenterDataManager.playerCenterVo.players <= _listVec.length -1)return;
			turnPage();
			planyerNumberChange();
			return;
			
			_listVec[_listVec.length -1].reset();
			_listVec[_listVec.length -1].setBg(_listVec.length - 1 );
			var item:ListItem;
			if(_playerCenterDataManager.playerCenterVo.players <  PlayerCenterDataConstant.MAX_PLAYER_NUMBER)
			{
				item = new ListItem();
				item.initUI();
				//				item.y = 26 * _target.numChildren;
				item.addPlayerNumber();
				item.callBack = addPlayerNumber;
				//				_target.addChild(item);
				_listVec.push(item);
			}
			//			planyerNumberChange();			
			//			_scrollBar.targetHeight = 26 *_target.numChildren;
		}
		/**
		 * 球员 体力和uBuff改变 
		 * pid为0 则所有的更新
		 * pid不为0 则更新单个
		 * @return 
		 * 
		 */
		public function changePowerAndBuff($obj:Object):void
		{
			if(!this.parent)return;
			if(!$obj.status)
			{
				return;
			}
			var len:int = _listVec.length;
			
//			restoreBtnStatus(false);
			var i:int;
			for(i = 0;i < len;i++)
			{
				
				if($obj.id == 0)
				{
					_listVec[i].updataValue();
					continue;
				}
				if(_listVec[i].data == null)return;
				if((_listVec[i].data as PlayerVo).playerid == $obj.id)
				{
					_listVec[i].updataValue();
//					_listVec[i].updataGoodsPanel($obj);
					break;
				}
			}
//			len = _playerList.length;
//			for(i = 0;i < len;i++)
//			{
//				if(_playerList[i].physical < _playerList[i].maxphysical)
//				{
//					restoreBtnStatus(true);
//					break;
//				}
//			}
			if(_selectItem == null)return;
			var vo:PlayerVo = _selectItem.data as PlayerVo
			showPlayerInfo(vo);
		}
		/**
		 *球员改变号码 
		 * @param $obj
		 * 
		 */
		public function changePlayerNumber($obj:Object):void
		{
			//			modificationBtn.addEventListener(MouseEvent.CLICK,onModificationHandler);
			//			if(!$obj.status)return;
			if(_modificationView != null)
				_modificationView.changePlayerNumber($obj);
			if(!$obj.status)return;
			var len:int = _listVec.length;
			for(var i:int = 0;i < len;i++)
			{
				if(_listVec[i].data == null)return;
				if((_listVec[i].data as PlayerVo).playerid == $obj.playerId)
				{
					_listVec[i].updataValue();
					break;
				}
			}
		}
//		/**
//		 *强力按钮状态 
//		 * @param $value true 可用，false不可用 
//		 * 体力不满的情况下强力按钮可用，体力全满的情况下强力按钮不可用
//		 * 
//		 */
//		private function restoreBtnStatus($value:Boolean):void
//		{
//			if($value)
//			{
//				restoreBtn.filters = null;
//				restoreBtn.mouseEnabled = true;
//			}else
//			{
//				var arr:Array = [new ColorMatrixFilter([0.5,0.5,0.5,0,0,
//					0.5,0.5,0.5,0,0,
//					0.5,0.5,0.5,0,0,
//					0,0,0,1,0,])];
//				restoreBtn.filters = arr;
//				restoreBtn.mouseEnabled = false;
//			}
//		}
		/**
		 *增加一个球员 
		 * @param $obj
		 * 
		 */
		public function addPlayer($obj:Object):void
		{
			
		}
		
		/**
		 *换页 
		 * @param $type
		 * 
		 */
		private function turnPage($type:String = ""):void
		{
			while(listcontain.numChildren)
			{
				listcontain.removeChildAt(0);
			}
			var arr:Array = ArrayUtil.getPageSizeDatas(_page.min,16,_playerList);
			var len:int = arr.length;
			for(var i:int = 0;i < len;i++)
			{
				_listVec[i].reset();
				_listVec[i].callBack = selectItem;
				_listVec[i].addBar();
				listcontain.addChild(_listVec[i]);
				_listVec[i].data = arr[i];
				if(i == 0)
					selectItem(_listVec[i]);
			}
			var num:int = AppData.getInstance().playerCenterDataManager.playerCenterVo.players;
			num = num - (_page.min - 1) * 16;
			
			for(i ;i <num;i++)
			{
				if(i >=16)break;
				_listVec[i].reset();
				listcontain.addChild(_listVec[i]);
				_listVec[i].removeBar();
			}
			for(;i < 16;i++)
			{
				_listVec[i].reset();
				_listVec[i].lockIconVisible = true;
				listcontain.addChild(_listVec[i]);
				_listVec[i].removeBar();
				_listVec[i].callBack = addPlayerNumber;
				_listVec[i].addEvtListener();
			}
		}
	}
}
